package com.yunyike.app.component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.rop.session.Session;
import com.rop.session.SessionManager;
import com.yunyike.app.redis.JedisManager;
import com.yunyike.app.response.ShopperSessionResponse;

public class SampleSessionManager implements SessionManager{
    protected final Logger logger = LoggerFactory.getLogger(getClass());

    private final Map<String, Session> sessionCache = new ConcurrentHashMap<String, Session>(128, 0.75f, 32);
    public static final int MAMCACHEDTIME = 7 * 24 * 60 * 60;

    public void addSession(String sessionId, Session session) {
//       sessionCache.put(sessionId, session);
	    try{
	    	JedisManager.setObject(sessionId, MAMCACHEDTIME, session);
	    } catch (Exception e) {
			e.printStackTrace();
		}
    }


    public ShopperSessionResponse getSession(String sessionId) {
//        return sessionCache.get(sessionId);
    	ShopperSessionResponse session = null;
        try {
        	session =  (ShopperSessionResponse) JedisManager.getObject(sessionId,ShopperSessionResponse.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return session;
    }


    public void removeSession(String sessionId) {
//        sessionCache.remove(sessionId);
        try {
        	JedisManager.delObject(sessionId);
        } catch (Exception e) {
			e.printStackTrace();
		}
    }
}

